package com.atguigu.srb.core.util;

import com.atguigu.srb.core.mapper.DictMapper;
import com.atguigu.srb.core.pojo.entity.Dict;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author lsyandwh
 * @create 2022-12-16 15:11
 */
public class DictUtils {

    public static String getDictName(BaseMapper<Dict> baseMapper,String code, Integer value){

        //1.根据dict_code查询父节点
        QueryWrapper<Dict> wrapper = new QueryWrapper<>();
        wrapper.eq("dict_code",code);

        Dict parentDict = baseMapper.selectOne(wrapper);

        //2.根据父节点id与value查询子节点
        wrapper.clear();

        wrapper.eq("parent_id",parentDict.getId())
                .eq("value",value);

        Dict dict = baseMapper.selectOne(wrapper);
        return dict.getName();
    }
}
